#!/bin/bash
date_time=0915
version=$2
aicard_num=$1

start_device=`expr $aicard_num \* 1`
end_device=`expr $aicard_num \* 1 + 2`
ph_card=`expr $aicard_num`

lock_file=r.lock_${aicard_num}

rm -f $lock_file
touch $lock_file

for device_id in `seq ${start_device} ${end_device}`
    do
            # echo device_id:$device_id  | tee -a ${CUR_PATH}/$log_file
            # sh hbm_run.sh ${device_id} $CURTIME --card_id_$ph_card $ph_card && echo $device_id >> $lock_file &
            # echo "1" >> r.lock
            log_path=../../log/${date_time}/${version}/$device_id
            mkdir -p $log_path
            log_file=$log_path/test.log

            rm -f $log_file
            touch $log_file

            # echo $device_id
            sh sdaarun.sh ${device_id} $log_file && echo $device_id>>$lock_file &
done

#while [[ $(cat $lock_file | wc -l) < 4 ]]; do
            # echo "11111"
#            sleep 1
#done


wait

# for device_id in `seq ${start_device} ${end_device}`
#     do
#             # echo device_id:$device_id  | tee -a ${CUR_PATH}/$log_file
#             # sh hbm_run.sh ${device_id} $CURTIME --card_id_$ph_card $ph_card && echo $device_id >> $lock_file &
#             # echo "1" >> r.lock
#             log_path=../../log/${date_time}/${version}/$device_id
#             mkdir -p $log_path
#             log_file=$log_path/test.log

#             if [ -f $log_file ];then
#                 result=$(cat $log_file | grep  'FAILED')
#                 length=$(expr length "$result")

#                 if [[ length -gt 0 ]];
#                 then
#                     flag=1
#                 fi
#                 # echo $log_file
#                 line=`cat $log_file | wc -l`
#                 # echo line:$line
#                 if [[ line -le 0 ]];
#                 then
#                     flag=1
#                 fi
#             else
#                 flag=1
#             echo  "log file not exists!!!"
#             fi

#             if [[ flag -gt 0 ]];
#             then
#                 echo -e "       device_$device_id RESULT: \E[31m [FAILED] \E[0m"
#             else
#                 echo -e "       device_$device_id RESULT: \E[32m [PASS] \E[0m"
#             fi
# done
